package com.tiance.demo.service.mysql.bo;

import com.tiance.demo.service.mysql.utils.ByteUtils;

public class FileHeader {

    /**
     * 一个文件头是38字节
     */
    public static final int SIZE = 38;

    private byte[] bytes;
    /**
     * 序列1 <br />
     * 4字节, 起始于: 0字节<br />
     * 页的校验和（checksum值）
     */
    private String spaceOrChksum;
    /**
     * 序列2 <br />
     * 4字节, 起始于: 4字节<br />
     * 页号
     */
    private int offset;
    /**
     * 序列3 <br />
     * 4字节, 起始于: 8字节<br />
     * 上一个页的页号
     */
    private int prev;
    /**
     * 序列4 <br />
     * 4字节, 起始于: 12字节<br />
     * 下一个页的页号
     */
    private int next;
    /**
     * 序列5 <br />
     * 8字节, 起始于: 16字节<br />
     * 页面被最后修改时对应的日志序列位置（英文名是：Log Sequence Number）
     */
    private String lsn;
    /**
     * 序列6 <br />
     * 2字节, 起始于: 24字节<br />
     * 该页的类型
     */
    private String type;
    /**
     * 序列7 <br />
     * 8字节, 起始于: 26字节<br />
     * 仅在系统表空间的一个页中定义，代表文件至少被刷新到了对应的LSN值
     */
    private String fileFlushLsn;
    /**
     * 序列8 <br />
     * 4字节, 起始于: 34字节<br />
     * 页属于哪个表空间
     */
    private int archLogNoOrSpaceId;

    public byte[] getBytes() {
        return bytes;
    }

    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }

    public String getSpaceOrChksum() {
        return spaceOrChksum;
    }

    public void setSpaceOrChksum(String spaceOrChksum) {
        this.spaceOrChksum = spaceOrChksum;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getPrev() {
        return prev;
    }

    public void setPrev(int prev) {
        this.prev = prev;
    }

    public int getNext() {
        return next;
    }

    public void setNext(int next) {
        this.next = next;
    }

    public String getLsn() {
        return lsn;
    }

    public void setLsn(String lsn) {
        this.lsn = lsn;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getFileFlushLsn() {
        return fileFlushLsn;
    }

    public void setFileFlushLsn(String fileFlushLsn) {
        this.fileFlushLsn = fileFlushLsn;
    }

    public int getArchLogNoOrSpaceId() {
        return archLogNoOrSpaceId;
    }

    public void setArchLogNoOrSpaceId(int archLogNoOrSpaceId) {
        this.archLogNoOrSpaceId = archLogNoOrSpaceId;
    }

    @Override
    public String toString() {
        return "FileHeader:\n" +
                "bytes=" + ByteUtils.bytes2HexStr(bytes) +
                "\nspaceOrChksum='" + spaceOrChksum + '\'' +
                ", offset=" + offset +
                ", prev=" + prev +
                ", next=" + next +
                ", lsn='" + lsn + '\'' +
                ", type='" + type + '\'' +
                ", fileFlushLsn='" + fileFlushLsn + '\'' +
                ", archLogNoOrSpaceId=" + archLogNoOrSpaceId +
                "\n----------------";
    }
}
